
************FEES
use "$data/2018_data.dta", clear
keep rate_spread total_points total_loan_cost origination_charge hoepa_stat loan_amount
drop if rate_spread=="NA"
destring rate_spread, replace force
keep if rate_spread~=.&rate_spread>4
destring total_points, replace force
destring total_loan, replace force
destring origin, replace force
destring hoepa, replace force
destring loan_amount, replace force
keep if loan_amount~=.
sum total_points if rate_spread>5&rate_spread<10&loan_amount>50000 
*average points and fees 2295.805
binscatter total_points rate_spread if rate_spread>5&rate_spread<10&loan_amount>50000, nquantiles(30) xline(6.5) line(none)
graph export "$figures/fees_more_2018.eps", as(eps) preview(off) replace

sum total_points if rate_spread>7&rate_spread<12&loan_amount<50000
*average points and fees 1126.355 
binscatter total_points rate_spread if rate_spread>7&rate_spread<12&loan_amount<50000, xline(8.5) line(none)
graph export "$figures/fees_less_2018.eps", as(eps) preview(off) replace



use "$data/2019_data.dta", clear
keep rate_spread total_points total_loan_cost origination_charge hoepa_stat loan_amount
drop if rate_spread=="NA"
destring rate_spread, replace force
keep if rate_spread~=.&rate_spread>4
destring total_points, replace force
destring total_loan, replace force
destring origin, replace force
destring hoepa, replace force
destring loan_amount, replace force
keep if loan_amount~=.

sum total_points if rate_spread>5&rate_spread<10&loan_amount>50000
*average points and fees 2323.446
binscatter total_points rate_spread if rate_spread>5&rate_spread<10&loan_amount>50000, nquantiles(30) xline(6.5) line(none)
graph export "$figures/fees_more_2019.eps", as(eps) preview(off) replace

sum total_points if rate_spread>7&rate_spread<12&loan_amount<50000
*average points and fees  1127.236
binscatter total_points rate_spread if rate_spread>7&rate_spread<12&loan_amount<50000, xline(8.5) line(none)
graph export "$figures/fees_less_2019.eps", as(eps) preview(off) replace









****************LTV

use "$data/2018_data.dta", clear
keep rate_spread total_points total_loan_cost origination_charge hoepa_stat loan_amount combined_loan
drop if rate_spread=="NA"
destring rate_spread, replace force
keep if rate_spread~=.&rate_spread>4
destring total_points, replace force
destring total_loan, replace force
destring origin, replace force
destring hoepa, replace force
destring loan_amount, replace force
destring combined_loan, replace force
keep if loan_amount~=.

binscatter combined_loan rate_spread if rate_spread>5&rate_spread<10&loan_amount>50000, nquantiles(30) xline(6.5) line(none)
graph export "$figures/ltv_more_2018.eps", as(eps) preview(off) replace

binscatter combined_loan rate_spread if rate_spread>7&rate_spread<12&loan_amount<50000, xline(8.5) line(none)
graph export "$figures/ltv_less_2018.eps", as(eps) preview(off) replace



use "$data/2019_data.dta", clear
keep rate_spread total_points total_loan_cost origination_charge hoepa_stat loan_amount combined_loan
drop if rate_spread=="NA"
destring rate_spread, replace force
keep if rate_spread~=.&rate_spread>4
destring total_points, replace force
destring total_loan, replace force
destring origin, replace force
destring hoepa, replace force
destring loan_amount, replace force
destring combined_loan, replace force
keep if loan_amount~=.


binscatter combined_loan rate_spread if rate_spread>5&rate_spread<10&loan_amount>50000, nquantiles(30) xline(6.5) line(none)
graph export "$figures/ltv_more_2019.eps", as(eps) preview(off) replace


binscatter combined_loan rate_spread if rate_spread>7&rate_spread<12&loan_amount<50000, xline(8.5) line(none)
graph export "$figures/ltv_less_2019.eps", as(eps) preview(off) replace



****************DTI

use "$data/2018_data.dta", clear
keep rate_spread total_points total_loan_cost origination_charge hoepa_stat loan_amount combined_loan debt_to_income_ratio
drop if rate_spread=="NA"
destring rate_spread, replace force
keep if rate_spread~=.&rate_spread>4
destring total_points, replace force
destring total_loan, replace force
destring origin, replace force
destring hoepa, replace force
destring loan_amount, replace force
destring combined_loan, replace force
destring debt_to_income_ratio, replace force
keep if loan_amount~=.

binscatter debt_to_income_ratio rate_spread if rate_spread>5&rate_spread<10&loan_amount>50000, nquantiles(30) xline(6.5) line(none)
graph export "$figures/dti_more_2018.eps", as(eps) preview(off) replace

binscatter debt_to_income_ratio rate_spread if rate_spread>7&rate_spread<12&loan_amount<50000, xline(8.5) line(none)
graph export "$figures/dti_less_2018.eps", as(eps) preview(off) replace



use "$data/2019_data.dta", clear
keep rate_spread total_points total_loan_cost origination_charge hoepa_stat loan_amount combined_loan debt_to_income_ratio

drop if rate_spread=="NA"
destring rate_spread, replace force
keep if rate_spread~=.&rate_spread>4
destring total_points, replace force
destring total_loan, replace force
destring origin, replace force
destring hoepa, replace force
destring loan_amount, replace force
destring combined_loan, replace force
destring debt_to_income_ratio, replace force
keep if loan_amount~=.

binscatter debt_to_income_ratio rate_spread if rate_spread>5&rate_spread<10&loan_amount>50000, nquantiles(30) xline(6.5) line(none)
graph export "$figures/dti_more_2019.eps", as(eps) preview(off) replace


binscatter debt_to_income_ratio rate_spread if rate_spread>7&rate_spread<12&loan_amount<50000, xline(8.5) line(none)
graph export "$figures/dti_less_2019.eps", as(eps) preview(off) replace
